//
//  ZGLConfirmationView.m
//  ZeegingLottery
//
//  Created by Alfa Li on 2018/6/9.
//  Copyright © 2018年 蒂埃里. All rights reserved.
//

#import "ZGLConfirmationView.h"

@interface ZGLConfirmationView ()<ZGLBeiShuPlusOrMinusDelegate>


@property (nonatomic, strong)UILabel *youHuaLabel;
@property (nonatomic, strong)UILabel *sumNoteLabel;       //总注数
@property (nonatomic, strong)UILabel *totalModeyLable;    //总金额
@property (nonatomic, strong)UILabel *forecastBonusesLab;   //预测奖金
@property (nonatomic, strong)UIView *bottomView;

@property (nonatomic, assign)NSInteger beiShuNum;



@end

@implementation ZGLConfirmationView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupUI];
        
    }
    
    return self;
}

#pragma mark - setter

- (void)setBetJSONDict:(NSDictionary *)betJSONDict
{
    if (betJSONDict) {
        _betJSONDict = betJSONDict;
        NSNumber *totalMoney = betJSONDict[@"amount"];
        NSNumber *betNum = betJSONDict[@"bet_num"];
        NSString *maxStr = [PublicMethod keepTwoDecimalPoint:betJSONDict[@"max_prize"]];
        NSString *minStr = [PublicMethod keepTwoDecimalPoint:betJSONDict[@"min_prize"]];
        
        self.sumNoteLabel.text = [NSString stringWithFormat:@"%@注",betNum];
        self.forecastBonusesLab.text = [NSString stringWithFormat:@"预计奖金：%@~%@元",minStr,maxStr];
        self.totalModeyLable.text = [NSString stringWithFormat:@"%@元",totalMoney];
        NSMutableAttributedString *strAtt = [[NSMutableAttributedString alloc] initWithString:self.totalModeyLable.text];
        [strAtt addAttribute:NSForegroundColorAttributeName value:globalRed range:NSMakeRange(0,strAtt.length-1)];
        self.totalModeyLable.attributedText = strAtt;
    }else{
        
        self.sumNoteLabel.text = @"0注";
        self.forecastBonusesLab.text = @"预计奖金：0.00~0.00元";
        self.totalModeyLable.text = @"0元";
        
    }
}



#pragma mark - setupUI

- (void)setupUI
{
    [self addSubview:self.youHuaLabel];
    
    UIView *line1 = [[UIView alloc]init];
    line1.backgroundColor = BorderColor;
    [self addSubview:line1];
    
//    [self addSubview:self.passwayBtn];
    [self addSubview:self.changeBeishu];
    [self addSubview:self.bottomView];
    [self addSubview:self.passwayButton];
    
    
    [_youHuaLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.equalTo(self).offset(20);
        make.right.equalTo(self).offset(-20);
        make.top.equalTo(self).offset(10);

    }];

    
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self);
        make.right.equalTo(self);
        make.height.equalTo(@(kBorderWidth));
        make.top.equalTo(_youHuaLabel.mas_bottom).offset(10);
        
    }];
    
    [_changeBeishu mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self).offset(-20);
        make.top.equalTo(line1).offset(10);
        make.height.equalTo(@(30));
        make.width.equalTo(@(150));
        
    }];
    
//    [_passwayBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.left.equalTo(self).offset(20);
//        make.centerY.equalTo(_changeBeishu);
//        make.height.equalTo(@(30));
//        make.width.equalTo(@(80));
//
//    }];
    
//    [_passwayButton mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.left.equalTo(self).offset(20);
//        make.top.equalTo(_changeBeishu);
//        make.height.equalTo(@(30));
//        make.width.equalTo(@80);
//
//    }];
    
    
    [_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self);
        make.bottom.equalTo(self);
        make.right.equalTo(self);
        make.top.equalTo(_changeBeishu.mas_bottom).offset(10);
        
    }];
    
    [self setupBottomView];
}

- (void)setupBottomView
{
    [_bottomView addSubview:self.submitScenariosBtn];
    [_bottomView addSubview:self.totalModeyLable];
    [_bottomView addSubview:self.sumNoteLabel];
    [_bottomView addSubview:self.forecastBonusesLab];
    
    
    [_submitScenariosBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_bottomView).offset(10);
        make.right.equalTo(self).offset(-20);
        make.height.equalTo(@(40));
        make.width.equalTo(@(100));
        
    }];
    
    [_totalModeyLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_submitScenariosBtn);
        make.right.equalTo(_submitScenariosBtn.mas_left).offset(-10);
        
    }];
    
    [_sumNoteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_totalModeyLable);
        make.right.equalTo(_totalModeyLable.mas_left).offset(-10);
//        make.left.equalTo(self).offset(20);
        
    }];
    
    [_forecastBonusesLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(_submitScenariosBtn);
        make.right.equalTo(_totalModeyLable);
        make.left.equalTo(self).offset(10);
        
    }];
}

#pragma mark - getter

- (UILabel *)youHuaLabel
{
    if (!_youHuaLabel) {
        _youHuaLabel = [[UILabel alloc]init];
        _youHuaLabel.text = @"注：全场90分钟(含伤停补时,不含加时赛及点球大战),页面奖金进攻参考,实际奖金以投注成功时为准";
        _youHuaLabel.textAlignment = 1;
        _youHuaLabel.numberOfLines = 0;
        _youHuaLabel.textColor = [UIColor grayColor];
        _youHuaLabel.font = [UIFont systemFontOfSize:labelFontSize];
    }
    return _youHuaLabel;
}

//- (UIButton *)passwayBtn
//{
//    if (!_passwayBtn) {
//        _passwayBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//        _passwayBtn.titleLabel.font = [UIFont systemFontOfSize:btnFontSize];
//        [_passwayBtn setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];
//        [_passwayBtn setBackgroundColor:[UIColor whiteColor]];
//        [_passwayBtn setBackgroundImage:[UIImage imageNamed:@"btn_section_title_arrow_down_pressed"] forState:UIControlStateNormal];
//        _passwayBtn.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
//        _passwayBtn.layer.cornerRadius = 3;
//        _passwayBtn.layer.borderColor = [UIColor grayColor].CGColor;
//        _passwayBtn.layer.borderWidth = BorderWidth;
//        
//        [_passwayBtn setTitle:@"过关方式" forState:UIControlStateNormal];
//        
//    }
//    
//    return _passwayBtn;
//}

- (LYDCustomButton *)passwayButton
{
    if (!_passwayButton) {
        _passwayButton = [[LYDCustomButton alloc]initWithFrame:CGRectMake(20, 54, 80, 30)];;
        [_passwayButton setBackgroundColor:[UIColor whiteColor]];
        _passwayButton.btuType = LeftTitleAndRightImage;
        _passwayButton.viewTitle = @"过关方式过关方式过关方式";
        _passwayButton.textColor = [UIColor blackColor];
        _passwayButton.textFont = [UIFont systemFontOfSize:btnFontSize];
        _passwayButton.viewImage = [UIImage imageNamed:@"feedbackDown"];
//        _passwayButton.imageSize = CGSizeMake(10, 22);
        _passwayButton.layer.cornerRadius = 3;
        _passwayButton.layer.borderColor = [UIColor grayColor].CGColor;
        _passwayButton.layer.borderWidth = kBorderWidth;
        
    }
    
    return _passwayButton;
}


- (ZGLBeiShuPlusOrMinus *)changeBeishu
{
    if (!_changeBeishu) {
        _changeBeishu = [[ZGLBeiShuPlusOrMinus alloc]init];
        _changeBeishu.delegate = self;
        self.beiShuNum = [_changeBeishu.beiShuBtn.titleLabel.text integerValue];;
        WS(weakself)
        _changeBeishu.beiShuNumBlock = ^(NSString *numStr) {
            
          weakSelf.beiShuNum = [numStr integerValue];
            DLog(@"回调倍数--%ld",weakSelf.beiShuNum);
            
            //
            [[NSNotificationCenter defaultCenter]postNotificationName:ZGLChangeBetContentJSON object:@(weakSelf.beiShuNum)];
            
        };
    }
    return _changeBeishu;
}

- (LSYButton *)submitScenariosBtn
{
    if (!_submitScenariosBtn) {
        _submitScenariosBtn = [LSYButton buttonWithType:UIButtonTypeCustom];
        [_submitScenariosBtn setTitle:@"确认购买" forState:UIControlStateNormal];
        [_submitScenariosBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _submitScenariosBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        _submitScenariosBtn.backgroundColor = sRGBHexAlpha(0xF63F3F, 1.0);
        _submitScenariosBtn.layer.cornerRadius = 5;
        _submitScenariosBtn.layer.masksToBounds = YES;
        
    }
    
    return _submitScenariosBtn;
}

- (UILabel *)totalModeyLable
{
    if (!_totalModeyLable) {
        _totalModeyLable = [[UILabel alloc]init];
        _totalModeyLable.textAlignment = 1;
        _totalModeyLable.font = [UIFont systemFontOfSize:15];
        _totalModeyLable.text = @"9999元";
        NSMutableAttributedString *strAtt = [[NSMutableAttributedString alloc] initWithString:_totalModeyLable.text];
        [strAtt addAttribute:NSForegroundColorAttributeName value:globalRed range:NSMakeRange(0,strAtt.length-1)];
        _totalModeyLable.attributedText = strAtt;
        
    }
    return _totalModeyLable;
}

- (UILabel *)sumNoteLabel
{
    if (!_sumNoteLabel) {
        _sumNoteLabel = [[UILabel alloc]init];
        _sumNoteLabel.textAlignment = 1;
        _sumNoteLabel.font = [UIFont systemFontOfSize:15];
        
        _sumNoteLabel.text = @"10注";
        
    }
    return _sumNoteLabel;
    
}

- (UILabel *)forecastBonusesLab
{
    if (!_forecastBonusesLab) {
        _forecastBonusesLab = [[UILabel alloc]init];
        _forecastBonusesLab.textAlignment = 2;
        _forecastBonusesLab.font = [UIFont systemFontOfSize:labelFontSize];
        _forecastBonusesLab.textColor = [UIColor lightGrayColor];
        
        _forecastBonusesLab.text = @"预计奖金：999.00~9999.99元";
    }
    return _forecastBonusesLab;
    
}

- (UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [[UIView alloc]init];
        _bottomView.backgroundColor = [UIColor whiteColor];
    }
    return _bottomView;
}

@end
